import json

from fastapi3 import APIRouter
from . import result

router_bigscreen = APIRouter(tags=["数据大屏管理"])


@router_bigscreen.get("/left/top", summary="左上图")
def chart_left_top():
    data = {
        "x": ["冰箱", "洗衣机", "电视机", "微波炉", "烤箱", "空调", "洗碗机"],
        "y": [1827, 342, 541, 1347, 2431, 876, 1578]
    }
    return result.success(data)


@router_bigscreen.get("/left/bottom", summary="左下图")
def chart_left_bottom():
    data = {
        "day": ["星期1", "星期2", "星期3", "星期4", "星期5", "星期6", "星期7"],
        "num": {
            "Clothes": [140, 232, 101, 264, 90, 340, 250],
            "digit": [120, 282, 111, 234, 220, 340, 310],
            "Electrical": [320, 132, 201, 334, 190, 130, 220],
            "gear": [220, 402, 231, 134, 190, 230, 120],
            "Chemicals": [220, 302, 181, 234, 210, 290, 150]
        }
    }
    return result.success(data)


@router_bigscreen.get("/right/top", summary="右上图")
def chart_right_top():
    data =  [
        {"value": 567, "name": "服饰"},
        {"value": 123, "name": "数码"},
        {"value": 324, "name": "家电"},
        {"value": 89, "name": "家居"},
        {"value": 453, "name": "日化"},
        {"value": 767, "name": "熟食"}
    ]
    return result.success(data)


@router_bigscreen.get("/right/bottom", summary="右下图")
def chart_right_bottom():
    data = {
        "day": ["星期1", "星期2", "星期3", "星期4", "星期5", "星期6", "星期7"],
        "num": {
            "Clothes": [320, 502, 401, 334, 390, 430, 720],
            "digit": [234, 564, 443, 234, 754, 430, 321],
            "Electrical": [220, 321, 335, 534, 390, 330, 310],
            "gear": [269, 212, 491, 368, 341, 330, 410],
            "Chemicals": [820, 832, 901, 934, 1290, 1330, 1320]
        }
    }
    return result.success(data)


@router_bigscreen.get("/map", summary="中间地图")
async def chart_map():
    with open("./data/china.json", "r", encoding="utf-8") as f:
        data = json.load(f)
    return result.success(data)
